@layout("/common/_curd/_container.html"){

<script type="text/javascript">
    var ctx = "${basePath}";
    var grid_selector = "#grid-table";
    var pager_selector = "#grid-pager";

    $(function(){
        initGrid();
        initMenuBtn("btns", "${code}");

    });

    function initGrid(){
        var id = '${id!}'
        var did = '${did!}'
        var grid_url = ctx + "/${code}/shouhuodetaillist?id="+id + "&&did="+did;
        console.log(grid_url)
        var _colnames = ["主键",
            "学校",
						"商品",
//						"审核状态",
            "生产日期",
            "备注",
            "数量",
            "规格",
            "操作"
        ];
        var _colmodel = [{name:"id", index:"id", hidden:true,width:100},
            {name:"schoolname", index:"schoolname", width:100},
            {name:"pname", index:"pname", width:100},
//						{name:"status", index:"status", width:100,formatter:function (value, row, index) {
//							if(value === 1){
//								return "已提交";
//							}else if(value ===2){
//								return "审核已通过";
//							}else if(value ===3){
//								return "审核未通过";
//							}
//						}},
            {name:"pdate", index:"pdate", width:100,formatter:function (value, row, index) {
                var v = value;
                if(!v){
                    v = ""
                }
//                if(index.status === 0){
//                    return  '<input type="date"  class="pdate" onblur="onchanges('+"'"+index.id+"'"+')" id="pdate'+index.id+'"   value="'+v+'"/>' ;
//                }else {
                    return v;
//                }


            }},
            {name:"remarks", index:"remarks", width:100,formatter:function (value, row, index) {
                var v = value;
                if(!v){
                    v = ""
                }
//                if(index.status === 0){
//                    return  '<input type="text" class="form-control remarks" id="remarks'+index.id+'" onblur="blurs('+"'"+index.id+"'"+')" value="'+v+'"/>' ;
//                }else {
                    return v;
//                }

            }},
            {name:"num", index:"num", width:100},
            {name:"unit", index:"unit", width:100},
            {name:"status", index:"status", width:100,formatter:function (value, row, index) {
                if(value === 0){
                    return "未发货";
                }else if(value === 3){
                    return  '<a href="#" class="btn btn-btn btn-success btn-xs"  onclick="shouhuo('+"'"+index.id+"'"+')">'+"确认收货"+'</a>'+
                            '<a href="#" class="btn btn-btn btn-danger btn-xs"  onclick="tuihuo('+"'"+index.id+"'"+')">'+"拒收"+'</a>';
                }else if(value === 4){
                    return  '<a href="#" class="btn btn-btn btn-danger btn-xs"  onclick="tuihuo('+"'"+index.id+"'"+')">'+"退货"+'</a>' ;
//                    return "已收货";
                }else if(value === 5){
                    return "异常";
                }else if(value === 6){
                    return "已退货";
                }


            }}
        ];

        jQuery(grid_selector).jqGrid({
            url : grid_url,
            shrinkToFit : true,
            colNames : _colnames,
            colModel : _colmodel,
            jsonReader : {id :"id"},
            pager : pager_selector,
            postData : {sort : "id",
//				where:"{uid:"+${uid!}+"}",
                order : "desc"}
        });
    }

    details = function (id) {
        layer.open({
            type: 2,
            title: '备货详单',
            shadeClose: true,
            area: ['90%', '90%'],
            content: '/buynum/beihuodetail'//iframe的url
            ,end:function () {
                $('#quantity').focus()
            }
        })
    }

//    onchanges = function (id) {
//        console.log('startup')
//        var value = $('#pdate'+id).val();
//        if(value != null || value != ""){
//            ajaxData = {id:id,value:value,type:'pdate'};
//            $.post("/buy/upby",ajaxData,function (res) {
//                if(res["success"]){
//                    layer.msg("操作成功！")
//                }
//            });
//        }
//    }
//
//    blurs = function (id) {
//        var value = $('#remarks'+id).val();
//        console.log(id+value )
//        if(value != null || value != ""){
//            ajaxData = {id:id,value:value,type:'remarks'};
//            $.post("/buy/upby",ajaxData,function (res) {
//                if(res["success"]){
//                    layer.msg("操作成功！")
//                }
//            });
//        }
//    }
    shouhuo = function (id) {
        ajaxData = {id:id,status:4};
        $.post("/buy/fahuo",ajaxData,function (res) {
            if(res["success"]){
                layer.msg("操作成功！", {shift: -1,time:100,end:function () {
                    jQuery("#grid-table").trigger("reloadGrid");
                }});
            }
        });
    }
    tuihuo = function (id) {
        ajaxData = {id:id,status:6};
        $.post("/buy/fahuo",ajaxData,function (res) {
            if(res["success"]){
                layer.msg("操作成功！", {shift: -1,time:100,end:function () {
                    jQuery("#grid-table").trigger("reloadGrid");
                }});
            }
        });
    }

    fahuoall = function () {
        layer.confirm("是否确定已收到全部货物！", {
            btn: ['确定','取消'] //按钮
        }, function(){
            ajaxData = {buynum:$("#buynumid").val(),status:4};
            console.log(ajaxData)
            $.post("/buy/fahuoall",ajaxData,function (res) {
                if(res["success"]){
                    layer.msg("操作成功！", {shift: -1,time:100,end:function () {
                        jQuery("#grid-table").trigger("reloadGrid");
                    }});
                }
            });
        });

    }

    //收货历史
    historyfahuo = function () {
//        jQuery("#grid-table").trigger("reloadGrid");
        $("#grid-table").jqGrid('setGridParam',{  // 重新加载数据
            postData: {
                "status": 4
            }
        }).trigger("reloadGrid");
    }
    //退货历史
    historytuihuo = function () {
//        jQuery("#grid-table").trigger("reloadGrid");
        $("#grid-table").jqGrid('setGridParam',{  // 重新加载数据
            postData: {
                "status": 6
            }
        }).trigger("reloadGrid");
    }

//    未收货
    weifahuo = function () {
        $("#grid-table").jqGrid('setGridParam',{  // 重新加载数据
            postData: {
                "status": 3
            }
        }).trigger("reloadGrid");
    }
</script>

<!--<script src="/static/blade/laydate/laydate.js"></script>-->
<!--<script>-->
    <!--laydate.render({-->
        <!--elem: '.pdate'-->
    <!--});-->
<!--</script>-->

<!--<script>-->
    <!--$(function () {-->
        <!--console.log("start")-->
<!--//        $('.remarks').each(function () {-->
<!--//            this.blur(function () {-->
<!--//                console.log("hhah")-->
<!--//            })-->
<!--//        })-->
        <!--console.log( $('input.remarks'))-->
        <!--$('input.remarks').focus(function () {-->
            <!--console.log("haha")-->
        <!--})-->
        <!--$('input.remarks').blur(function () {-->
            <!--console.log("haha")-->
        <!--})-->
    <!--})-->
<!--</script>-->

 <input type="hidden" id="buynumid" value="${id!}">
<!-- 配置 grid -->
<div class="row">
    <button href="#" class="btn btn-btn btn-success btn-xs" style="margin-left:12px;" onclick="fahuoall()">全部收货</button>
    <button href="#" class="btn btn-btn btn-primary btn-xs" style="margin-left:12px;" onclick="weifahuo()">未收货</button>
    <button href="#" class="btn btn-btn btn-warning btn-xs" style="margin-left:12px;" onclick="historyfahuo()">已收货</button>
    <button href="#" class="btn btn-btn btn-danger btn-xs" style="margin-left:12px;" onclick="historytuihuo()">已退货</button>
    <div class="col-xs-12 tb-grid">
        <!-- 配置 查询 -->
        <!-- 按钮 -->
        <!--<div class="welljq well-sm" id="btns"></div>-->
        <!-- grid -->
        <table id="grid-table"></table>
        <!-- 分页-->
        <div id="grid-pager"></div>
    </div>
</div>

<!-- 引入所需的js -->
@include("/common/_listscript.html"){}

@}